package com.mqz.zebraEcommerce.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;

//自定义校验器
public class IsShowConstraintValidator implements ConstraintValidator<IsShowValidate, Integer> {
//    private Set<Integer> set = new HashSet<>();

    //    @Override
//    public void initialize(EnumValidate constraintAnnotation) {
//        int[] values = constraintAnnotation.values();
//        for (int value : values) {
//            set.add(value);
//        }
//    }
//
//    @Override
//    public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
//        return set.contains(value);
//    }
    private String regexp = "";

    @Override
    public void initialize(IsShowValidate constraintAnnotation) {
        regexp = constraintAnnotation.regexp();
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
        return value.toString().matches(regexp);
    }
}
